package com.jxm.bootstudy.service;

import com.jxm.bootstudy.listener.MyEvent;
import com.jxm.bootstudy.pojo.User;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Author: jxm
 * @Description:
 * @Date: 2024-1-5 15:18
 * @Version: 1.0
 */
@Service
public class UserService {

    @Resource
    private ApplicationContext applicationContext;

    /**
     * 发布事件
     * @return
     */
    public User getUser2() {
        User user = new User(1l, "倪升武", "123456");
        // 发布事件
        MyEvent event = new MyEvent(this, user);
        applicationContext.publishEvent(event);
        return user;
    }
}
